<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Utils\ModelOperatorTrait;

class PrintConfigController extends Controller
{
    use ModelOperatorTrait;


    protected function model(){
        return app(\App\Models\PrintConfig::class);
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $printConfigs = $this->pageModel($request->all());

        return formatJsonResponse($printConfigs);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        
        try {
            \DB::beginTransaction();

            $othor = $request->othor;

            $printConfigs = $this->dropModel(['type' => $request->type]);

            foreach($othor as $reqeustData){

                $reqeustData['type'] = $request->type;

                $this->storeModel($reqeustData);
            }

            \DB::commit();
        } catch (\Exception $e) {
            \DB::rollback();

            return formatJsonResponse(null,$e->getMessage(),10009);
        }
        

        return formatJsonResponse();
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
